package cn.t.persistence.mapper.order;

import cn.t.model.order.OrderDetailDO;
import cn.t.model.order.OverPickupRecordVO;
import cn.t.persistence.entity.order.OverPickupRecordPO;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 超领记录表(OverPickupRecord)领域对象与实体对象转换
 *
 * @author t
 * @since 2024-05-24 10:18:10
 */

public interface OverPickupRecordMapper extends BaseMapper<OverPickupRecordPO> {
    @Select({
            "<script>",
            "SELECT",
            "o.device_id, o.card_code, o.cost_center_name, pr.id, o.firm_id, pr.work_order_sn, o.gmt_close," +
                    " o.user_name, d.device_name ," +
                    "pr.order_sn,pr.time_limit_type,pr.quantity_limit,pr.pickup_qty,pr.over_qty,pr.sku_code,pr.sku_name,pr.type ",
            "FROM t_over_pickup_record pr ",
            "LEFT JOIN t_order o ON pr.order_sn = o.order_sn ",
            "LEFT JOIN t_device d ON d.id = o.device_id ",
            "${ew.customSqlSegment}", // 这里添加分页动态SQL片段
            "</script>"
    })
    @Results({
            @Result(column = "device_id", property = "deviceId"),
            @Result(column = "card_code", property = "cardCode"),
            @Result(column = "firm_id", property = "firmId"),
            @Result(column = "work_order_sn", property = "workOrderSn"),
            @Result(column = "gmt_close", property = "gmtCreated"),
            @Result(column = "user_name", property = "userName"),
            @Result(column = "device_name", property = "deviceName"),
            @Result(column = "order_sn", property = "orderSn"),
            @Result(column = "cost_center_name", property = "costCenterName"),
            @Result(column = "time_limit_type", property = "timeLimitType"),
            @Result(column = "quantity_limit", property = "quantityLimit"),
            @Result(column = "pickup_qty", property = "pickupQty"),
            @Result(column = "over_qty", property = "overQty"),
            @Result(column = "sku_code", property = "skuCode"),
            @Result(column = "sku_name", property = "skuName"),
            @Result(column = "type", property = "type"),
    })
    List<OverPickupRecordVO> queryOverPickupRecordList(@Param("ew") Wrapper<OverPickupRecordPO> wrapper);
    @Select({
            "<script>",
            "SELECT",
            "o.device_id, o.card_code, replace(u.phone_number,'\"','') phone_number,o.user_id, o.cost_center_name, pr.id, o.firm_id, pr.work_order_sn, o.gmt_close,o.gmt_created," +
                    " o.user_name, d.device_name ," +
                    "pr.order_sn,pr.time_limit_type,pr.quantity_limit,pr.pickup_qty,pr.over_qty,pr.sku_code,pr.sku_name,pr.type ",
            "FROM t_over_pickup_record pr ",
            "LEFT JOIN t_order o ON pr.order_sn = o.order_sn ",
            "LEFT JOIN t_device d ON d.id = o.device_id ",
            " JOIN t_user_query u ON u.id = o.user_id  and u.user_Status=0",
            "${ew.customSqlSegment}",
            "</script>"
    })
    @Results({
            @Result(column = "device_id", property = "deviceId"),
            @Result(column = "phone_number", property = "phoneNumber"),
            @Result(column = "card_code", property = "cardCode"),
            @Result(column = "firm_id", property = "firmId"),
            @Result(column = "work_order_sn", property = "workOrderSn"),
            @Result(column = "gmt_close", property = "gmtCreated"),
            @Result(column = "user_name", property = "userName"),
            @Result(column = "device_name", property = "deviceName"),
            @Result(column = "order_sn", property = "orderSn"),
            @Result(column = "cost_center_name", property = "costCenterName"),
            @Result(column = "time_limit_type", property = "timeLimitType"),
            @Result(column = "quantity_limit", property = "quantityLimit"),
            @Result(column = "pickup_qty", property = "pickupQty"),
            @Result(column = "over_qty", property = "overQty"),
            @Result(column = "sku_code", property = "skuCode"),
            @Result(column = "sku_name", property = "skuName"),
            @Result(column = "type", property = "type"),
    })
    /**
     * 查询禁用的用户的超领单
     */
    List<OverPickupRecordVO> queryOverPickupRecordLock( @Param("ew") Wrapper<OverPickupRecordPO> wrapper);

   List<OrderDetailDO> pickupTotalNum();

}
